package com.gitee.huxing.course.conc.conc02.atomic;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.conc02
 * @ClassName: AtomicMain
 * @Author: huxing
 * @DateTime: 2021-08-23 上午10:04
 */
public class AtomicMain {

    public static void main(String[] args) throws Exception{
        final SyncCount syncCount = new SyncCount();
        final AtomicCount atomicCount = new AtomicCount();
        LocalDateTime startTime = LocalDateTime.now();
        for (int i=0; i< 100; i++){
            new Thread(() -> {
                for (int j= 0; j< 10000; j++){
                    syncCount.add();
                    atomicCount.add();
                }
            }).start();
        }
        Thread.sleep(5000L);
        LocalDateTime endTime = LocalDateTime.now();
        Duration duration = Duration.between(startTime, endTime);
        System.out.println("线程执行完成时间:::" + duration.getSeconds());
        System.out.println("1-sync num=" + syncCount.getNum());
        System.out.println("1-atomic num=" + atomicCount.getNum());

    }
}
